// $URL: http://mingw-lib.googlecode.com/svn/trunk/working/4u_dump/widget.h $
// $Rev: 89 $
// $Author: akio.miyoshi $
// $Date:: 2010-05-19 06:08:48 +0000#$

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QtCore>
#include <QtSql>
#include "nam.h"

//class Rec4U : public QObject {
//    Q_OBJECT
class Rec4U {
public:
    QString key;
    QString title;
    QString link;
    QString guid;
    QString media_content;
    QString media_thumbnail;
    QString media_bitmap;
    QString pubDate;
    //QString description;
    friend QDebug operator<< (QDebug d, const Rec4U &model)
    {
        d << "{Rec4U:";
        d << "\n";
        d << "<key>" << model.key;
        d << "\n";
        d << "<title>" << model.title;
        d << "\n";
        d << "<link>" << model.link;
        d << "\n";
        d << "<guid>" << model.guid;
        d << "\n";
        d << "<media_content>" << model.media_content;
        d << "\n";
        d << "<media_thumbnail>" << model.media_thumbnail;
        d << "\n";
        d << "<media_bitmap>" << model.media_bitmap;
        d << "\n";
        d << "<pubDate>" << model.pubDate;
        d << "\n";
        //QString html = model.description;
        //d << "<description>" << html.replace( QRegExp("<[^>]*>"), "" );
        //d << "\n";
        d << "}";
        return d;
    }
};

namespace Ui {
    class Widget;
}

class Widget : public QWidget {
    Q_OBJECT
public:
    Widget(QWidget *parent = 0);
    ~Widget();

protected:
    void changeEvent(QEvent *e);

private:
    Ui::Widget *ui;
    NetworkAccessManager *nam;
    QSqlDatabase m_db;
    void setDesktopFile(QFile &file, QString name);
    void saveDesktopFile(QString name, QByteArray bytes);
    void backupXmlBody(QByteArray bytes);
    int addPageFor4U(int pageNo);
    int parseXmlFor4U(QByteArray &xml, QList<Rec4U> &result);
    QDateTime parseDateTime4U(QString pubDateStr);
    int addDataFor4U(int pageNo);

private slots:
    void on_pushButton_3_clicked();
    void on_pushButton_4_clicked();
    void on_pushButton_2_clicked();
    void on_pushButton_clicked();
public slots:
    void submit();
    void submit2(QString a_url);
    void populateJavaScriptWindowObject1();
    void populateJavaScriptWindowObject2();
};

#endif // WIDGET_H
